import request from '@/utils/request'

/**
 * 获取文章
 * @param {*} id id
 * @param {*} timestamp 时间戳
 * @returns
 */
export const getArticleList = (id, timestamp) => {
  return request({
    method: 'get',
    url: '/v1_1/articles',
    params: {
      channel_id: id,
      timestamp,
      with_top: 1
    }
  })
}

/**
 * 文章不感兴趣
 * @param {Number} id id
 * @returns
 */
export function dislikeArticle (id) {
  return request({
    method: 'POST',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}

/**
 * 举报文章
 * @param {*} id 文章id
 * @param {*} type 举报类型
 * @returns
 */
export function reportArticle (id, type) {
  return request({
    method: 'POST',
    url: '/v1_0/article/reports',
    data: {
      target: id,
      type
    }
  })
}

/**
 * 获取文章详情
 * @param {*} id id
 * @returns
 */
export function getArticleDetail (id) {
  return request({
    method: 'get',
    url: '/v1_0/articles/' + id
  })
}

/**
 * 关注用户
 * @param {*} id 被关注用户的id
 * @returns
 */
export function followUser (id) {
  return request({
    method: 'post',
    url: '/v1_0/user/followings',
    data: {
      target: id
    }
  })
}

/**
 * 取消关注
 * @param {*} id 被关注用户的id
 * @returns
 */
export const unfollowUser = (id) => {
  return request({
    method: 'delete',
    url: '/v1_0/user/followings/' + id
  })
}

/**
 * 给文章点赞
 * @param {*} articleId 文章id
 * @returns
 */
export const addLike = (articleId) => {
  return request({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: articleId
    }
  })
}

/**
 * 取消对文章点赞
 * @param {*} articleId 文章id
 * @returns
 */
export const deleteLike = (articleId) => {
  return request({
    method: 'delete',
    url: '/v1_0/article/likings/' + articleId
  })
}

/**
 * 对文章不喜欢
 * @param {*} articleId 文章id
 * @returns
 */
export const addDisLike = (articleId) => {
  return request({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target: articleId
    }
  })
}

/**
 * 取消对文章不喜欢
 * @param {*} articleId 文章id
 * @returns
 */
export const deleteDisLike = (articleId) => {
  return request({
    method: 'DELETE',
    url: '/v1_0/article/dislikes/' + articleId
  })
}

/**
 * 获取评论
 * @param {*} articleId 文章id
 * @param {*} offset 上一次返回的id， 如果是第一页，可以为null
 * @returns
 */
export const getCommentList = (articleId, offset) => {
  return request({
    method: 'get',
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: articleId,
      offset: offset
    }
  })
}

/**
 * 发布评论
 * @param {*} articleId 文章id
 * @param {*} content 发布的内容
 * @returns
 */
export const addComment = (articleId, content) => {
  return request({
    method: 'post',
    url: '/v1_0/comments',
    data: {
      target: articleId,
      content
    }
  })
}

/**
 * 对评论点赞
 * @param {*} commentId 点赞的评论id
 * @returns
 */
export const addCommentZan = (commentId) => {
  return request({
    method: 'post',
    url: '/v1_0/comment/likings',
    data: {
      target: commentId
    }
  })
}

/**
 * 对评论取消点赞
 * @param {*} commentId 点赞的评论id
 * @returns
 */
export const deleteCommentZan = (commentId) => {
  return request({
    method: 'DELETE',
    url: '/v1_0/comment/likings/' + commentId
  })
}

/**
 * 获取回复评论
 * @param {*} commentId 评论的id
 * @param {*} offset 上一次返回的id， 如果是第一页，可以为null
 * @returns
 */
export const getCommentReply = (commentId, offset) => {
  return request({
    method: 'get',
    url: '/v1_0/comments',
    params: {
      type: 'c',
      source: commentId,
      offset: offset
    }
  })
}

/**
 * 对评论进行回复
 * @param {*} commentId 评论的id
 * @param {*} content 评论的内容
 * @param {*} artId 文章的id
 * @returns
 */
export const addReply = (commentId, content, artId) => {
  return request({
    method: 'post',
    url: '/v1_0/comments',
    data: {
      target: commentId,
      content: content,
      art_id: artId
    }
  })
}
